<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>重理学生管理系统 - 登录</title>
    <style>
        * {
            margin: 0;
            padding: 0;
            box-sizing: border-box;
        }

        body {
            font-family: 'Microsoft YaHei', Arial, sans-serif;
            display: flex;
            justify-content: center;
            align-items: center;
            min-height: 100vh;
            background: linear-gradient(120deg, #2980b9, #8e44ad);
            padding: 20px;
        }

        .login-container {
            background-color: rgba(255, 255, 255, 0.95);
            padding: 40px;
            border-radius: 15px;
            box-shadow: 0 15px 35px rgba(0, 0, 0, 0.2);
            width: 100%;
            max-width: 400px;
            text-align: center;
        }

        .system-title {
            color: #2c3e50;
            margin-bottom: 30px;
            font-size: 28px;
            font-weight: bold;
            text-shadow: 1px 1px 2px rgba(0, 0, 0, 0.1);
        }

        .system-subtitle {
            color: #7f8c8d;
            margin-bottom: 30px;
            font-size: 16px;
        }

        .form-group {
            margin-bottom: 20px;
            position: relative;
        }

        .form-group input {
            width: 100%;
            padding: 12px 15px;
            font-size: 16px;
            border: 2px solid #ddd;
            border-radius: 8px;
            outline: none;
            transition: all 0.3s ease;
        }

        .form-group input:focus {
            border-color: #3498db;
            box-shadow: 0 0 8px rgba(52, 152, 219, 0.3);
        }

        .login-btn {
            width: 100%;
            padding: 12px;
            background: #3498db;
            color: white;
            border: none;
            border-radius: 8px;
            font-size: 16px;
            font-weight: bold;
            cursor: pointer;
            transition: all 0.3s ease;
            margin-top: 10px;
        }

        .login-btn:hover {
            background: #2980b9;
            transform: translateY(-2px);
            box-shadow: 0 5px 15px rgba(0, 0, 0, 0.2);
        }

        .login-btn:active {
            transform: translateY(0);
        }

        .school-info {
            margin-top: 20px;
            color: #95a5a6;
            font-size: 14px;
        }

        @media (max-width: 480px) {
            .login-container {
                padding: 30px 20px;
            }

            .system-title {
                font-size: 24px;
            }
        }

        /* 添加输入框图标 */
        .form-group i {
            position: absolute;
            left: 15px;
            top: 50%;
            transform: translateY(-50%);
            color: #7f8c8d;
        }

        /* 错误提示样式 */
        .error-message {
            color: #e74c3c;
            font-size: 14px;
            margin-top: 5px;
            display: none;
        }
    </style>
    <!-- 添加图标库 -->
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.15.4/css/all.min.css">
</head>
<body>
    <div class="login-container">
        <h1 class="system-title">重理学生管理系统</h1>
        <p class="system-subtitle">Chongqing University of Technology</p>
        
        <form id="loginForm" action="login" method="POST">
            <div class="form-group">
                <input type="text" name="account" placeholder="请输入账号" required>
                <div class="error-message" id="account-error">请输入有效的账号</div>
            </div>
            <div class="form-group">
                <input type="password" name="password" placeholder="请输入密码" required>
                <div class="error-message" id="password-error">请输入有效的密码</div>
            </div>
            <button type="submit" class="login-btn">登 录</button>
        </form>
        <div class="school-info">
            © 2025 重庆理工大学
        </div>
    </div>

<script>
    document.getElementById('loginForm').addEventListener('submit', function (e) {
        e.preventDefault();
        
        // 重置错误提示
        document.querySelectorAll('.error-message').forEach(el => el.style.display = 'none');
        
        var formData = new FormData(this);
        var account = formData.get('account').trim();
        var password = formData.get('password').trim();
        
        // 简单的表单验证
        let hasError = false;
        if (!account) {
            document.getElementById('account-error').style.display = 'block';
            hasError = true;
        }
        if (!password) {
            document.getElementById('password-error').style.display = 'block';
            hasError = true;
        }
        
        if (hasError) return;

        var xhr = new XMLHttpRequest();
        xhr.open('POST', 'login', true);
        xhr.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
        xhr.onreadystatechange = function () {
            if (xhr.readyState === 4) {
                if (xhr.status === 200) {
                    if (xhr.responseText.trim() === 'success') {
                        window.location.href = 'index.html';
                    } else {
                        alert('账号或密码错误');
                    }
                } else {
                    alert('服务器错误，请稍后重试');
                }
            }
        };
        var params = new URLSearchParams(formData).toString();
        xhr.send(params);
    });

    // 添加输入框焦点效果
    document.querySelectorAll('input').forEach(input => {
        input.addEventListener('focus', function() {
            this.parentElement.classList.add('focused');
        });
        input.addEventListener('blur', function() {
            this.parentElement.classList.remove('focused');
        });
    });
</script>
</body>
</html>